home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / prog / buletq10.zip / BC_LAI10.C < prev    next >
C/C++ Source or Header  |  1992-05-31  |  6KB  |  256 lines

  1.  
  2. #include <dos.h>
  3. #include <conio.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <stdarg.h>
  7. #include <time.h>
  8.  
  9. #include "BULLET.h"
  10.  
  11. /*
  12.  bb_lai10.c 31-May-92 chh
  13.  --test raw speed using 32-bit long integer key, unique
  14.  1) this test uses a non-standard binary field as a sort field
  15.  2) this code is for raw speed tests--it's straight inline
  16.  
  17.  Note: memory model must be medium, large, or huge
  18.  
  19. For Turbo C 2.0:
  20.  
  21.  C>tcc -mm bc_lai10 BULLET.lib
  22.  
  23.  
  24. For Quick C 2.50 (v2.50 *must not* use ATEXITXB (define QC250 to not)):
  25.  
  26.  C>tcl -Am bc_lai10 BULLET.lib
  27.  
  28. */
  29.  
  30. /* #define QC250 sux */
  31.  
  32. struct memorypack MP;
  33. struct initpack IP;
  34. struct exitpack EP;
  35. struct fielddesctype fieldlist[2];
  36. struct createdatapack CDP;
  37. struct createkeypack CKP;
  38. struct dosfilepack DFP;
  39. struct openpack OP;
  40. struct accesspack AP;
  41. struct exitpack EP;
  42.  
  43. int    rez, level;
  44. div_t    div_rez;
  45. time_t    starttime, endtime;
  46.  
  47. char    tmpstr[129];
  48.  
  49. char     NameDAT[] = ".\\BINTEST.DBB\0";
  50. char     NameIX1[] = ".\\BINTEST.IX1\0";
  51.  
  52. char    kx1[] = "CODENUMBER\0";
  53.  
  54. unsigned handdat, handix1;
  55.  
  56. struct testrectype {
  57.     char  tag[1];
  58.     long  codenumber;
  59.     char  codename[11];
  60. }; /* 16 */
  61. struct testrectype testrec;
  62.  
  63. char    keybuffer[64];
  64.  
  65. long    recs2add;
  66. long    low;
  67. long    high;
  68. long    i;
  69.  
  70.  
  71. int main()
  72. {
  73.  
  74.    strcpy(fieldlist[0].fieldname, "CODENUMBER");
  75.    strcpy(fieldlist[0].fieldtype, "B");
  76.    fieldlist[0].fieldlen = 4;
  77.    fieldlist[0].fielddc = 0;
  78.    strcpy(fieldlist[1].fieldname, "CODENAME");
  79.    strcpy(fieldlist[1].fieldtype, "C");
  80.    fieldlist[1].fieldlen = 11;
  81.    fieldlist[1].fielddc = 0;
  82.  
  83.    /* yes, it's been a while since my last C coding, like 1985  */
  84.    /* ...just something to get used to...it's okay, though      */
  85.  
  86.    /* clrscr(); */
  87.    printf("BC_LAI10.C - LONG INT, SIGNED, UNIQUE long int, add/reindex speed test\n");
  88.    printf("--uses non-standard data files with binary field values, not DBF\n");
  89.    printf(">> USING DIRECTORY : .\\ \n\n");
  90.  
  91.    level = 100;
  92.    MP.func = MEMORYXB;
  93.    rez = BULLET(&MP);
  94.    printf("memory avail   : %lu\n",MP.memory);
  95.  
  96.    if (MP.memory < 40000l) {
  97.       rez = 8;
  98.       goto Abend;
  99.    }
  100.  
  101.    level = 110;
  102.    IP.func = INITXB;
  103.    IP.jftmode = 0;
  104.    rez = BULLET(&IP);
  105.    if (rez != 0) goto Abend;
  106.  
  107.    /* --------------------------------------------------------------------
  108.       Quick C uses a near _atexit for both medium and large standard LIBs
  109.       This is of course a bug! and it prevents the use of ATEXITXB. This
  110.       is with at least QC 2.50. If you experience a lock-up using ATEXITXB
  111.       then you know what the problem is. Easy enough to get a fix. Call MS.
  112.       And the problem is also in crt0dat. Turbo C operates correctly. */
  113.  
  114. #ifndef QC250
  115.    level = 120;
  116.    EP.func = ATEXITXB;
  117.    rez = BULLET(&EP);
  118.    if (rez != 0) goto Abend;
  119. #endif
  120.  
  121.    level = 130;                /* disregard not found errors */
  122.    DFP.func = DELETEFILEDOS;
  123.    DFP.filenameptr = NameDAT;
  124.    rez = BULLET(&DFP);
  125.    DFP.filenameptr = NameIX1;
  126.    rez = BULLET(&DFP);
  127.  
  128.    level = 1000;
  129.    CDP.func = CREATEDXB;
  130.    CDP.filenameptr = NameDAT;
  131.    CDP.nofields = 2;
  132.    CDP.fieldlistptr = fieldlist;
  133.    CDP.fileid = 255;
  134.    rez = BULLET(&CDP);
  135.    if (rez !=0) goto Abend;
  136.  
  137.    level = 1010;
  138.    OP.func = OPENDXB;
  139.    OP.filenameptr = NameDAT;
  140.    OP.asmode = READWRITE | DENYNONE;
  141.    rez = BULLET(&OP);
  142.    if (rez !=0) goto Abend;
  143.    handdat = OP.handle;
  144.  
  145.    level = 1100;
  146.    CKP.func = CREATEKXB;
  147.    CKP.filenameptr = NameIX1;
  148.    CKP.keyexpptr = kx1;
  149.    CKP.xblink = handdat;
  150.    CKP.keyflags = cLONG | cSIGNED | cUNIQUE;
  151.    CKP.codepageid = -1;
  152.    CKP.countrycode = -1;
  153.    CKP.collateptr = NULL;
  154.    rez = BULLET(&CKP);
  155.    if (rez !=0) goto Abend;
  156.  
  157.    level = 1110;
  158.    OP.func = OPENKXB;
  159.    OP.filenameptr = NameIX1;
  160.    OP.asmode = READWRITE | DENYNONE;
  161.    OP.xblink = handdat;
  162.    rez = BULLET(&OP);
  163.    if (rez !=0) goto Abend;
  164.    handix1 = OP.handle;
  165.  
  166.    AP.func = ADDRECORDXB;
  167.    AP.handle = handdat;
  168.    AP.recptr = &testrec;
  169.    AP.keyptr = keybuffer;
  170.    AP.nextptr = NULL;
  171.  
  172.    strcpy(testrec.tag," \0");
  173.    strcpy(testrec.codename, "xxxSAMExxxx\0");
  174.  
  175.    printf("Recs to add/reindex: ");
  176.    gets(tmpstr);
  177.    recs2add = atol(tmpstr);
  178.    if (recs2add == 0L) recs2add = 5L;
  179.  
  180.    level = 1200;
  181.    low = -3L;
  182.    high = low + recs2add - 1L;
  183.    printf("Adding %ld records ( keys %ld to %ld )... ",recs2add,low,high);
  184.  
  185.    time(&starttime);
  186.    for (i = low; i < (recs2add+low); i++) {
  187.       testrec.codenumber = i;
  188.       rez = BULLET(&AP);
  189.       if (rez !=0) goto Abend;
  190.    }
  191.    time(&endtime);
  192.    printf("%lu secs.\n",(endtime - starttime));
  193.  
  194.    level = 1210;
  195.    printf("Reindexing... ");
  196.    AP.func = REINDEXXB;
  197.    AP.handle = handix1;
  198.    time(&starttime);
  199.    rez = BULLET(&AP);
  200.    time(&endtime);
  201.    if (rez != 0) goto Abend;
  202.    printf("%lu secs\n\n",(endtime - starttime));
  203.  
  204.    level = 1300;
  205.    AP.func = GETFIRSTXB;
  206.    rez = BULLET(&AP);
  207.    printf("  The first 5 key/recs\n");
  208.    printf("%7lu %7ld %.11s\n",AP.recno,testrec.codenumber,testrec.codename);
  209.    for (i=1;i < 5; i++) {
  210.       if (rez != 0) break;
  211.       AP.func = GETNEXTXB;
  212.       rez = BULLET(&AP);
  213.       printf("%7lu %7ld %.11s\n",AP.recno,testrec.codenumber,testrec.codename);
  214.    }
  215.    if (rez == 202) rez = 0;
  216.    if (rez != 0) goto Abend;
  217.    puts(" ");
  218.  
  219.    level = 1310;
  220.    AP.func = GETLASTXB;
  221.    rez = BULLET(&AP);
  222.    printf("  The last 5 key/recs\n");
  223.    printf("%7lu %7ld %.11s\n",AP.recno,testrec.codenumber,testrec.codename);
  224.    for (i=1;i < 5; i++) {
  225.       if (rez != 0) break;
  226.       AP.func = GETPREVXB;
  227.       rez = BULLET(&AP);
  228.       printf("%7lu %7ld %.11s\n",AP.recno,testrec.codenumber,testrec.codename);
  229.    }
  230.    if (rez == 203) rez = 0;
  231.    if (rez != 0) goto Abend;
  232.  
  233.    puts("Okay.");
  234.    EP.func = EXITXB;
  235.    rez = BULLET(&EP);
  236.    return(0);
  237.    /* program exit */
  238.  
  239.  
  240.    /*----------------------------------------------*/
  241.    /* that's right, we go to a termination routine */
  242.  
  243. Abend:
  244.    printf("Error: %u at level %u while performing ",rez,level);
  245.    switch (level) {
  246.    case 100:
  247.       printf("a memory request of 140K.\n");
  248.       break;
  249.    default:
  250.       printf("(See source)\n");    /* just check the source */
  251.    }
  252.  
  253.    exit(1);
  254. }
  255.  
  256.